package com.itestor.iptv.modules.common.dao;

import java.util.List;

import org.hibernate.Query;
import com.itestor.iptv.global.dao.GenericHibernateDao;
import com.itestor.iptv.modules.common.domain.RoleGroup;
import com.itestor.iptv.modules.common.domain.UserAccount;

/**
 * @author Mr.li 
 */
public class TbUserDao extends GenericHibernateDao<UserAccount, Integer> {

    /**
     * 按用户名查找.
     * @param username 用户名
     * @return TbUser 用户
     */
    public UserAccount find(String username) {
        StringBuilder hql = new StringBuilder();
        hql.append("from UserAccount t where t.username=:username");
        Query query = getHibernateSession().createQuery(hql.toString());
        query.setParameter("username", username);
        return getEntity(query);
    }
    
    /**
     * 获取权限组列表
     * @return List
     */
    @SuppressWarnings("unchecked")
    public List<RoleGroup> findAllRoleGroup() {
        StringBuilder hql = new StringBuilder();
        hql.append("from RoleGroup t order by t.roleGroupName desc");        
        Query query = getHibernateSession().createQuery(hql.toString());
        
        return query.list();
    }
    

}